<?php

namespace app\common\model\xilujob;

use think\Cache;
use think\Model;


class SiteCity extends Model
{

    

    

    // 表名
    protected $name = 'xilujob_site_city';
    const CACHE_KEY = 'site_cities';

    // 追加属性
    protected $append = [
        'status_text'
    ];


    
    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    public static function getAll($useCache=true) {
        $cacheKey = self::CACHE_KEY;
        $all = Cache::get($cacheKey);
        if(!$all || !$useCache) {
            $all = static::where('status',1)->order('weigh','desc')->select();
            Cache::set($cacheKey, $all, 3600);
        }
        return $all;
    }


}
